package birdry.utils	{
	
	//	birdry.utils.ColorUtil;
	
	import com.greensock.TweenLite;
	import fl.motion.Color;
	
	public class ColorUtil		{
		
		/**
		 * 0xRRGGBB 형태로 텍스트를 표시해주는 함수..
		 * 0x023F  ---> 0x00023F 
		 * @param value
		 * @return 
		 */		
		public static function  rgbToHEX( value: String ): String
		{
			var len: int = 6 - value.length;
			var tmp: String = "";
			for( var i: int=0; i<len; i++ ){
				tmp += "0";
			}
			return tmp + value;
		}
		
		public static function hexToRGB( color:uint ): Object	{
			var r:uint = (color >> 16);
			var g:uint = (color >> 8 % 0xFF);
			var b:uint = (color & 0XFF);
			return {r:r, g:g, b:b};
		}
		
		/**
		 * 랜덤컬러 추출
		 * @return 
		 * 
		 */		
		public static function  randomColor(): uint		{
			return Math.random() * 0xFFFFFF;
		}
		
		
		
		public static function betweenRandomColor(color1:uint, color2:uint): uint	{
			var r1:uint = ( color1 >> 16 );
			var g1:uint = ( color1 >> 8 & 0xFF );
			var b1:uint = ( color1 & 0xFF );
			var r2:uint = ( color2 >> 16 );
			var g2:uint = ( color2 >> 8 & 0xFF );
			var b2:uint = ( color2 & 0xFF );
			 
			var small:Number = g2 / g1;
				 
			var offSet:Number = Math.random() * ( 1 - small ) + small ;

			r1 *= offSet;
			g1 *= offSet;
			b1 *= offSet;
			var color:uint = r1 << 16 | g1 << 8 | b1;
			return color;
		}
		
		/**
		 * 시작과 끝나는 컬러값의 중간 값을 구한다.
		 * @param	startColor
		 * @param	endColor
		 * @param	value   0~1
		 */
		public static function interpolateColor( startColor:uint, endColor:uint, value:Number ): uint	{
			return Color.interpolateColor (startColor, endColor, value);
		}
		
		/**
		 * 특정 색상의 밝기 값 추출
		 * @param	color
		 * @return
		 */
		public static function getBrightness( color: uint ): Number	{
			// red channel
			var nr = color >> 16 & 0xff;
			// green channel
			var ng = color >> 8 & 0xff;
			// blue channel
			var nb = color & 0xff;
			// brightness
			return Math.round(Math.sqrt(nr * nr + ng * ng + nb * nb));
		}
	}
}